package org.example.code.test2024.eight_mouth;

import java.util.Deque;
import java.util.LinkedList;

class MinStack {
    private Deque<Integer> stack = null;
    private Deque<Integer> minStack = null;

    public MinStack() {
        stack = new LinkedList<>();
        minStack = new LinkedList<>();
        minStack.push(Integer.MAX_VALUE);
    }
    
    public void push(int val) {
        stack.offerFirst(val);
        minStack.push(Math.min(minStack.peek(), val));
    }
    
    public void pop() {
        Integer x = stack.getFirst();
        stack.removeFirst();
        minStack.remove(x);

    }
    
    public int top() {
        Object[] x = stack.toArray();
        return stack.getFirst();
    }
    
    public int getMin() {
        Object[] x = minStack.toArray();
        for(Object i:x){
            System.out.println(i);
        }
        int n = x.length;
        int y =(Integer) x[n-1];
        return y;
    }
}

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.push(val);
 * obj.pop();
 * int param_3 = obj.top();
 * int param_4 = obj.getMin();
 */